<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
/**
 * By		o熊小猫o
 * Email	show1990@foxmail.com
 *
 */
class Monitor extends CI_Controller {
	
	public function __construct() {
		parent::__construct ();
	}
	
	function index() {
		ignore_user_abort ();//即使Client断开(如关掉浏览器)，PHP脚本也可以继续执行
		set_time_limit ( 0 );//执行时间为无限制，php默认的执行时间是30秒，通过set_time_limit(0)可以让程序无限制的执行下去
		$interval = 30; //$interval = 60 * 5;//每隔5分钟运行
		do {
			$apiUrl = "http://uapi.115.com/?ct=upload_api&ac=get_pick_code_info&pickcode=dn05aatk&version=1176";
			$curlObj = curl_init ();
			curl_setopt ( $curlObj, CURLOPT_URL, $apiUrl );
			curl_setopt ( $curlObj, CURLOPT_RETURNTRANSFER, 1 );
			curl_setopt ( $curlObj, CURLOPT_SSL_VERIFYPEER, 0 );
			curl_setopt ( $curlObj, CURLOPT_HEADER, 0 );
			curl_setopt ( $curlObj, CURLOPT_HTTPHEADER, array ('Content-type:application/json' ) );
			$response = curl_exec ( $curlObj );
			curl_close ( $curlObj );
			$json = json_decode ( $response );
			$message = $json->Message;
			if ($message != 'ok') {
				{
					$config ['protocol'] = 'smtp'; //协议
					$config ['charset'] = '	utf-8'; //字符集
					$config ['smtp_port'] = 25; //端口
					$config ['smtp_host'] = 'smtp.163.com'; //服务器
					$config ['smtp_user'] = 'zhuanbj@163.com'; //用户名
					$config ['smtp_pass'] = 'buzhidao'; //密码
					$this->load->library ( 'email', $config );
					$this->email->from ( 'zhuanbj@163.com', 'o熊小猫o' ); //发件人email地址和名称
					$this->email->to ( 'show1990@foxmail.com' ); //收件人
					$this->email->subject ( '监测异常' );
					$this->email->message ( '监测异常，请及时检查程序接口' );
					$query = $this->email->send ();
					if ($query) {
						//echo '邮件发送';//$this->email->print_debugger();
					} else {
						//echo $this->email->print_debugger();
					}
				}
			}
			
			//等待5分钟
			sleep ( $interval );
		} while ( true );
	}
}

/* End of file monitor.php */
/* Location: ./application/controllers/monitor.php */